package com.wash.shoes.controller.pc;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.ShopGoodsTypePo;
import com.wash.shoes.service.ShopGoodsTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ljg
 * @since 2024-12-01
 */
@Api(tags = {"PC-商品的分类"})
@RestController
@RequestMapping({"/shopGoodsType", "/dev-api/shopGoodsType"})
public class ShopGoodsTypeController {


    @Autowired
    ShopGoodsTypeService shopGoodsTypeService;

    @ApiOperation("获取商品类型列表")
    @PostMapping("/list")
    public R<Page<ShopGoodsTypePo>> pageList(@RequestBody ShopGoodsTypePo shopGoodsTypePo) {
        Page<ShopGoodsTypePo> page = shopGoodsTypeService.pageList(shopGoodsTypePo);
        return R.ok(page);
    }

    @ApiOperation("修改新增,有id为修改没有为新增")
    @PostMapping("/saveUpdate")
    public R<String> add(@RequestBody ShopGoodsTypePo shopGoodsTypePo) {
        if (ObjectUtil.isEmpty(shopGoodsTypePo.getId())) {
            shopGoodsTypePo.setStatus(1);
            shopGoodsTypeService.save(shopGoodsTypePo);
        } else {
            shopGoodsTypeService.updateById(shopGoodsTypePo);
        }
        return R.ok();
    }

    @ApiOperation("逻辑删除 修改 status为0")
    @PostMapping("/deleteByStatus")
    public R<ShopGoodsTypePo> deleteByStatus(String theId) {

        ShopGoodsTypePo shopGoodsTypePo = shopGoodsTypeService.getById(theId);
        shopGoodsTypePo.setStatus(0);
        shopGoodsTypeService.updateById(shopGoodsTypePo);
        return R.ok(shopGoodsTypePo);
    }

    @ApiOperation("获取详情")
    @PostMapping("/getDetailById")
    public R<ShopGoodsTypePo> getDetailById(String theId) {
        ShopGoodsTypePo shopGoodsTypePo = shopGoodsTypeService.getById(theId);
        return R.ok(shopGoodsTypePo);
    }

}

